package com.peng.leetcode.string;

/**
 * AddStrings
 *
 * @author: lupeng6
 * @create: 2023/2/23 10:56
 */
public class AddStrings {
    public static void main(String[] args) {

        System.out.println(new AddStrings().addStrings("11", "123"));
    }

    public String addStrings(String num1, String num2) {
        int i = num1.length() - 1;
        int j = num2.length() - 1;
        int add = 0;
        StringBuilder res = new StringBuilder();
        while (i >= 0 || j >= 0 || add != 0) {
            int n1 = i >= 0 ? num1.charAt(i) - '0' : 0;
            int n2 = j >= 0 ? num2.charAt(j) - '0' : 0;
            int sum = n1 + n2 + add;
            res.append(sum % 10);
            add = sum / 10;
            i--;
            j--;
        }
        res.reverse();
        return res.toString();
    }
}
